package com.lc.afbx.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.lc.afbx.BaseApplication;
import com.lc.afbx.R;
import com.lc.afbx.conn.GetApiShowStore;

import java.util.HashMap;
import java.util.List;

/**
 * Created by Administrator on 2016/6/25.
 */
public class ShopAdapter extends BaseAdapter {
    private List<GetApiShowStore.Data> dataList;
    private LayoutInflater inflater;
    public HashMap<Integer, Boolean> isCheck;

    public ShopAdapter(Context context, List<GetApiShowStore.Data> dataList) {
        inflater = LayoutInflater.from(context);
        this.dataList = dataList;

        isCheck = new HashMap<>();
        for (int i = 0; i < dataList.size(); i++) {
            isCheck.put(i, false);
        }
    }

    public void init() {
        for (int i = 0; i < dataList.size(); i++) {
            isCheck.put(i, false);
        }
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;

        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_shop, null);
            BaseApplication.ScaleScreenHelper.loadView((ViewGroup) convertView);
            holder = new ViewHolder();

            holder.title = (TextView) convertView.findViewById(R.id.shopName);
            holder.address = (TextView) convertView.findViewById(R.id.shopAddress);
            holder.check = (CheckBox) convertView.findViewById(R.id.shopCheck);


            convertView.setTag(holder);

        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.title.setText(dataList.get(position).title);
        holder.address.setText(dataList.get(position).cur_address);
        holder.check.setChecked(isCheck.get(position));

        return convertView;
    }

    class ViewHolder {
        TextView title, address;
        CheckBox check;
    }
}
